package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlSocial;
import com.ruoyi.sl.service.ISlSocialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社保维护Controller
 * 
 * @author admin
 * @date 2024-06-17
 */
@RestController
@RequestMapping("/sl/social")
public class SlSocialController extends BaseController
{
    @Autowired
    private ISlSocialService slSocialService;

    /**
     * 查询社保维护列表
     */
    @PreAuthorize("@ss.hasPermi('sl:social:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlSocial slSocial)
    {
        startPage();
        List<SlSocial> list = slSocialService.selectSlSocialList(slSocial);
        return getDataTable(list);
    }

    /**
     * 导出社保维护列表
     */
    @PreAuthorize("@ss.hasPermi('sl:social:export')")
    @Log(title = "社保维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlSocial slSocial)
    {
        List<SlSocial> list = slSocialService.selectSlSocialList(slSocial);
        ExcelUtil<SlSocial> util = new ExcelUtil<SlSocial>(SlSocial.class);
        util.exportExcel(response, list, "社保维护数据");
    }

    /**
     * 获取社保维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:social:query')")
    @GetMapping(value = "/{userName}")
    public AjaxResult getInfo(@PathVariable("userName") String userName)
    {
        return success(slSocialService.selectSlSocialByUserName(userName));
    }

    /**
     * 新增社保维护
     */
    @PreAuthorize("@ss.hasPermi('sl:social:add')")
    @Log(title = "社保维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlSocial slSocial)
    {
        slSocial.setCreateBy(getUsername());
        return toAjax(slSocialService.insertSlSocial(slSocial));
    }

    /**
     * 修改社保维护
     */
    @PreAuthorize("@ss.hasPermi('sl:social:edit')")
    @Log(title = "社保维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlSocial slSocial)
    {
        slSocial.setUpdateBy(getUsername());
        return toAjax(slSocialService.updateSlSocial(slSocial));
    }

    /**
     * 删除社保维护
     */
    @PreAuthorize("@ss.hasPermi('sl:social:remove')")
    @Log(title = "社保维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{socialIds}")
    public AjaxResult remove(@PathVariable Long[] socialIds)
    {
        return toAjax(slSocialService.deleteSlSocialBySocialIds(socialIds));
    }
}
